/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package reamodel.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectWithInverseResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

import reamodel.Commitment;
import reamodel.EconomicAgentType;
import reamodel.EconomicResourceType;
import reamodel.ReamodelPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Commitment</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link reamodel.impl.CommitmentImpl#getName <em>Name</em>}</li>
 *   <li>{@link reamodel.impl.CommitmentImpl#getResource <em>Resource</em>}</li>
 *   <li>{@link reamodel.impl.CommitmentImpl#getAgent <em>Agent</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public abstract class CommitmentImpl extends EObjectImpl implements Commitment {
	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getResource() <em>Resource</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getResource()
	 * @generated
	 * @ordered
	 */
	protected EList<EconomicResourceType> resource;

	/**
	 * The cached value of the '{@link #getAgent() <em>Agent</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAgent()
	 * @generated
	 * @ordered
	 */
	protected EList<EconomicAgentType> agent;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected CommitmentImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return ReamodelPackage.Literals.COMMITMENT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, ReamodelPackage.COMMITMENT__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<EconomicResourceType> getResource() {
		if (resource == null) {
			resource = new EObjectWithInverseResolvingEList.ManyInverse<EconomicResourceType>(EconomicResourceType.class, this, ReamodelPackage.COMMITMENT__RESOURCE, ReamodelPackage.ECONOMIC_RESOURCE_TYPE__SPECIFY);
		}
		return resource;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<EconomicAgentType> getAgent() {
		if (agent == null) {
			agent = new EObjectWithInverseResolvingEList.ManyInverse<EconomicAgentType>(EconomicAgentType.class, this, ReamodelPackage.COMMITMENT__AGENT, ReamodelPackage.ECONOMIC_AGENT_TYPE__SPECIFY);
		}
		return agent;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ReamodelPackage.COMMITMENT__RESOURCE:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getResource()).basicAdd(otherEnd, msgs);
			case ReamodelPackage.COMMITMENT__AGENT:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getAgent()).basicAdd(otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case ReamodelPackage.COMMITMENT__RESOURCE:
				return ((InternalEList<?>)getResource()).basicRemove(otherEnd, msgs);
			case ReamodelPackage.COMMITMENT__AGENT:
				return ((InternalEList<?>)getAgent()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case ReamodelPackage.COMMITMENT__NAME:
				return getName();
			case ReamodelPackage.COMMITMENT__RESOURCE:
				return getResource();
			case ReamodelPackage.COMMITMENT__AGENT:
				return getAgent();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case ReamodelPackage.COMMITMENT__NAME:
				setName((String)newValue);
				return;
			case ReamodelPackage.COMMITMENT__RESOURCE:
				getResource().clear();
				getResource().addAll((Collection<? extends EconomicResourceType>)newValue);
				return;
			case ReamodelPackage.COMMITMENT__AGENT:
				getAgent().clear();
				getAgent().addAll((Collection<? extends EconomicAgentType>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case ReamodelPackage.COMMITMENT__NAME:
				setName(NAME_EDEFAULT);
				return;
			case ReamodelPackage.COMMITMENT__RESOURCE:
				getResource().clear();
				return;
			case ReamodelPackage.COMMITMENT__AGENT:
				getAgent().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case ReamodelPackage.COMMITMENT__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case ReamodelPackage.COMMITMENT__RESOURCE:
				return resource != null && !resource.isEmpty();
			case ReamodelPackage.COMMITMENT__AGENT:
				return agent != null && !agent.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //CommitmentImpl
